﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mojo;

namespace HelloWorld
{
    public class HelloWorldTemplate : Template
    {

        //since this method is marked with "PerContext" , the actual implementation
        //will only be called _once_ per context and then cached inside the context
        //(this is done via AOP by NAspect)

        // PerCall      = create each time the object is requested
        // PerGraph     = create once per root call and reuse during the complete call flow 
        // PerContext   = create once per context
        // PerThread    = create a new for each thread the object is requested from
        
        [FactoryMethod(InstanceMode.PerContext)]
        public virtual IGreeter Greeter()
        {
            ConsoleGreeter greeter = CreateObject<ConsoleGreeter>();
            greeter.ForeColor = ConsoleColor.Yellow;
            greeter.BackColor = ConsoleColor.DarkGray;
            greeter.Text = "Contract object says Hello World!";

            return greeter;
        }


        //This method is marked as "DefaultForType" , this means that 
        //the result of this method will be used when fetching objects by type only
        //eg:  context.GetObject<IGreeter>();

        [FactoryMethod(FactoryType.DefaultForType,InstanceMode.PerContext)]
        public virtual IGreeter DefaultGreeter()
        {
            ConsoleGreeter greeter = CreateObject<ConsoleGreeter>();
            greeter.ForeColor = ConsoleColor.Green;
            greeter.BackColor = ConsoleColor.DarkGray;
            greeter.Text = "Default object says Hello World!";

            return greeter;
        }

        [FactoryMethod("My Named Greeter", InstanceMode.PerContext)]
        public virtual IGreeter NamedGreeter()
        {
            ConsoleGreeter greeter = CreateObject<ConsoleGreeter>();
            greeter.ForeColor = ConsoleColor.Magenta;
            greeter.BackColor = ConsoleColor.DarkGray;
            greeter.Text = "Named object says Hello World!";

            return greeter;
        }        
    }
}
